//
//  SLLevelStarView.m
//  StarLight
//
//  Created by Duke.wu on 16/6/6.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLLevelStarView.h"

@interface SLLevelStarView ()

@property (nonatomic, strong)UIImageView *starImg1;

@property (nonatomic, strong)UIImageView *starImg2;

@property (nonatomic, strong)UIImageView *starImg3;

@property (nonatomic, strong)UIImageView *starImg4;

@property (nonatomic, strong)UIImageView *starImg5;

@end


@implementation SLLevelStarView


- (instancetype)init{
  if(self = [super init]){
    [self addSubview:self.starImg1];
    [self addSubview:self.starImg2];
    [self addSubview:self.starImg3];
    [self addSubview:self.starImg4];
    [self addSubview:self.starImg5];
    
    [self.starImg1 mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.top.equalTo(self);
      make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    
    [self.starImg2 mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.starImg1.mas_right);
      make.top.equalTo(self.starImg1);
      make.size.equalTo(self.starImg1);
    }];
    
    [self.starImg3 mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.starImg2.mas_right);
      make.top.equalTo(self.starImg1);
      make.size.equalTo(self.starImg1);
    }];
    
    [self.starImg4 mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.starImg3.mas_right);
      make.top.equalTo(self.starImg1);
      make.size.equalTo(self.starImg1);
    }];
    
    [self.starImg5 mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.starImg4.mas_right);
      make.top.equalTo(self.starImg1);
      make.size.equalTo(self.starImg1);
    }];
    
  }
  return self;
}




- (void)setLevelStarWithLevel:(NSInteger)level{
  for (int i = 0; i < 5; i ++) {
    UIImageView *star = [self viewWithTag:100 + i];
    if (i < level) {
      [star setImage:[UIImage imageNamed:@"等级钻_Blue"]];
    }else{
      [star setImage:[UIImage imageNamed:@"等级钻_Gary"]];
    }
  }
}

- (UIImageView *)backImageView{
  UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"等级钻_Gary"]];
  return image;
}

- (UIImageView *)starImg1{
  if(!_starImg1){
    _starImg1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"等级钻_Blue"]];
    _starImg1.tag = 100;
  }
  return _starImg1;
}

- (UIImageView *)starImg2{
  if(!_starImg2){
    _starImg2 = [self backImageView];
    _starImg2.tag = 101;
  }
  return _starImg2;
}

- (UIImageView *)starImg3{
  if(!_starImg3){
    _starImg3 = [self backImageView];
    _starImg3.tag = 102;
  }
  return _starImg3;
}

- (UIImageView *)starImg4{
  if(!_starImg4){
    _starImg4 = [self backImageView];
    _starImg4.tag = 103;
  }
  return _starImg4;
}

- (UIImageView *)starImg5{
  if(!_starImg5){
    _starImg5 = [self backImageView];
    _starImg5.tag = 104;
  }
  return _starImg5;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
